<?php

/**
 * MVM_MALL 网上商店系统  后台顶部文件
 * ============================================================================
 * 版权所有 (C) 2007-2010 www.mvmmall.com，并保留所有权利。
 * 网站地址: http://www.mvmmall.com
 * ----------------------------------------------------------------------------
 * 这是一个免费开源的软件；这意味着您可以在不用于商业目的的前提下对程序代码
 * 进行修改、使用和再发布。
 * ============================================================================
 * $Author:  www.mvmmall.com  $
 * $Date: 2008-02-27 $
 * $Id: index.inc.php www.mvmmall.com$
 * ---------------------------------------------
*/

if(!defined('MVMMALL') || !defined('IN_ADMINCP')) {
    exit('Access Denied');
}
//删除购物车数据库
if ($mm_stock_time < 9000){
  $cart_del_time = $m_now_time - (60 * 60 * $mm_stock_time);
  $db->query("DELETE FROM `{$tablepre}cart_table` WHERE cart_wish = '0' AND register_date < '$cart_del_time' ");
}

//删除系统日志数据
if ($mm_use_deldb > 1){
  $db_del_time = $m_now_time - (60 * 60 * 24 * $mm_use_deldb);
  $db->query("DELETE FROM `{$tablepre}login_table` WHERE register_date < '$db_del_time'");//登陆日志
  $db->query("DELETE FROM `{$tablepre}manager_table` WHERE register_date < '$db_del_time'");//管理日志
  $db->query("DELETE FROM `{$tablepre}search_table` WHERE register_date < '$db_del_time'");//搜索日志
}
//定单统计
$order_nums   = 0;
$pay_nums     = 0;
$pay_amount   = 0.00;
$order_amount = 0.00;
$start_date = mktime(0,0,0,date('m',$m_now_time),date('d',$m_now_time),date('Y',$m_now_time));
$result = $db->query("SELECT order_amount,addtime,status FROM `{$tablepre}order_info`  WHERE addtime > $start_date");
while($rt = $db->fetch_array($result)) {
    $order_nums++;
    $order_amount+=$rt['order_amount'];
    if ($rt['status']==2){
        $pay_nums++;
        $pay_amount+=$rt['order_amount'];
    }
}
//end
if ($frame=='top') {
	$result = $db->query("SELECT * FROM `{$tablepre}admin_menu` WHERE menu_id = '0'   ORDER BY menu_id,menu_order");
	while ($rs=$db->fetch_array($result)) {
		$top_arr .="'".$rs['uid']."'".',';
		$rs_cat[]=$rs; 
	}
	$top_arr.="'".'home'."'";
include template('top');	
}elseif ($frame=='menu'){
	$one_cat = $db->get_all("SELECT * FROM `{$tablepre}admin_menu` WHERE menu_id = '0'   ORDER BY menu_id,menu_order");
include template('menu');	
}elseif ($frame=='main'){
	$counter_list = $db->get_one("SELECT * FROM `{$tablepre}counter_table` WHERE uid = '1'");
	$start_date = mktime(0,0,0,date("m",$m_now_time),date("d",$m_now_time),date("Y",$m_now_time));
	$result = $db->query("SELECT member_id,member_name,member_email,register_date FROM `{$tablepre}member_table` WHERE register_date > $start_date");
	$now_num = 0;
	while($list = $db->fetch_array($result)) {
		$now_member .= "[".$list['member_id']."(".$list['member_name'].":".$list['member_email'].")]\n";
		$now_num++;
	}

	$b_jumin = date("md",$m_now_time);
	$result = $db->query("SELECT member_id,member_name,member_email,member_jumin,member_birthday from `{$tablepre}member_table` WHERE substring(member_jumin,3,4) = '$b_jumin' or substring(member_birthday,5,4) = '$b_jumin'");
	$b_num = 0;
	while($list = $db->fetch_array($result)) {
		$b_member .= "[".$list[member_id]."(".$list[member_name].":".$list[member_email].")]\n";
		$b_num++;
	}
	$result = $db->query("SELECT SUM(a.buy_number) as total_num,a.goods_name,a.order_id,a.goods_id,a.buy_price,b.uid,b.addtime,b.status,c.uid,c.goods_stock,c.goods_cost,c.goods_file1 FROM `{$tablepre}order_goods` a INNER JOIN `{$tablepre}order_info` b ON a.order_id=b.uid INNER JOIN `{$tablepre}goods_table` c ON a.goods_id=c.uid WHERE b.status>1 AND b.status<8 GROUP BY a.goods_id  ORDER BY total_num DESC LIMIT 0,20");
	while($rt = $db->fetch_array($result)) {
		$co_num++;
		$rt['total_sale'] = currency($rt['buy_price']*$rt['total_num']);
		$rt['url']        = GetBaseUrl('product',$rt['goods_id']);
		$rt['num']        = $co_num;
		$cart_rt[]        = $rt;
	}
	$mysql_support = mysql_get_server_info();
	$server        = "$_SERVER[SERVER_SIGNATURE]/".PHP_VERSION;
	include template('main');
footer();
}else {
	
include template('index');
}